﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 超市收银系统
{
    class SuperMarket
    {
        CangKu cangku = new CangKu();
        public SuperMarket()
        {
            cangku.GetProducts("Acer笔记本", 1000);
            cangku.GetProducts("Banana", 100000);
            cangku.GetProducts("JiangYou", 20000);
            cangku.GetProducts("SanXing", 2000);


        }
        //用户买商品
        public void BuyProducts()
        {
            //CangKu cangku = new CangKu();
            Console.WriteLine("请问您需要什么商品？我们这里有Acer笔记本、Banana、JiangYou、SanXing");
            string product = Console.ReadLine();
            Console.WriteLine("请问你需要多少？");
            int count = Convert.ToInt32(Console.ReadLine());
            ProductFather[] products = cangku.OutProducts(product, count);
            double money = GetMoney(products);
            Console.WriteLine("总共{0}元", money);
            Console.WriteLine("请选择客户所享受的折扣：1--不打折，2--打95折，3--满500送50");
            string input = Console.ReadLine();
            Console.WriteLine("打完折后您应付{0}元", Discount(input).GetTotalMoney(money));

        }
        public DiscountFather Discount(string input)
        {
            DiscountFather discount = null;
            switch (input)
            {
                case "1":
                    discount = new DiscountReal();
                    break;
                case "2":
                    discount = new DiscountRate(0.95);
                    break;
                case "3":
                    discount = new DiscountBuySong(500, 50);
                    break;
            }
            return discount;
        }

        public double GetMoney(ProductFather[] products)
        {
            double money = 0;
            for (int i = 0; i < products.Length; i++)
            {
                money += products[i].Price;
            }
            return money;
        }
        public void ShowSuperMarket()
        {
            cangku.ShowProducts();
        }
    }
}
